package GameEngine.Drawables.Tile;

import java.util.HashMap;


import processing.core.PImage;

public class TileImageBuffer {
	private int size = 256;
	private HashMap<String, ImageIdxPair> HBuffer = new HashMap<String, ImageIdxPair>();
	private int last;

	public TileImageBuffer() {
		this(256); // Defaultgroesse ist 256
	}

	private TileImageBuffer(int sz) {
		size = sz;
		HBuffer.clear();
		clear();
	}

	private void clear() {
		last = 0;
	}

	public int add(PImage img, String fname) {
		if (last < size) {
			HBuffer.put(fname, new ImageIdxPair(img, last, fname));
			last++;
		}
		return -1; // Buffer ist voll
	}

	public ImageIdxPair get(String fname) {
		return HBuffer.get(fname);
	}

	// Getter/Setter

	public int getSize() {
		return size;
	}

	public int getLast() {
		return last;
	}

	public boolean fullyLoaded() {
		for (ImageIdxPair ip : HBuffer.values()) {
			if (ip.img.width == 0) {
				return false;
			}
		}
		return true;
	}
}
